package com.jsh.ex.controller;

import com.jsh.ex.convert.Pager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by wukai on 2017/9/11.
 */
@ApiIgnore
@RestController
public class IndexController {
    Logger logger = LoggerFactory.getLogger(this.getClass());
    @RequestMapping(value = "/index")
    public String index(){
        return "hello spring-boot";
    }

    @RequestMapping(value = "/getPager")
    public String getPage(@RequestParam("pager") Pager pager){
        int pageNo = pager.getPageNo();
        int pageSize = pager.getPageSize();

        return "pageNo is: " + pageNo + ", pageSize is: " + pageSize;
    }

    @RequestMapping(value = "/setSess")
    public Map<String,Object> setSess(HttpServletRequest request){
        Map<String,Object> map = new HashMap<>();
        request.getSession().setAttribute("request Url",request.getRequestURL());
        map.put("request Url",request.getRequestURL());
        map.put("id",request.getSession().getId());
        return map;
    }

    @RequestMapping(value = "/getSess")
    public Object getSess(HttpServletRequest request){
        Map<String,Object> map = new HashMap<>();
        map.put("id",request.getSession().getId());
        map.put("message",request.getSession().getAttribute("request Url"));
        return map;
    }

}
